package com.example.pcl.controller.admin;

import com.example.pcl.constant.MessageConstants;
import com.example.pcl.pojo.dto.AdminCommentDTO;
import com.example.pcl.pojo.dto.AdminCommentFilterDTO;
import com.example.pcl.pojo.vo.AdminCommentVO;
import com.example.pcl.result.PageResult;
import com.example.pcl.result.Result;
import com.example.pcl.service.IHealthKnowledgeCommentsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 健康知识评论表，记录用户对心理健康知识的评论 前端控制器
 * </p>
 *
 * @author xx
 * @since 2024-12-17
 */
@RestController("adminHealthKnowledgeCommentsController")
@RequestMapping("/admin/mhkComment")
@Slf4j
@Tag(name = "管理端健康知识评论相关接口")
@RequiredArgsConstructor
public class HealthKnowledgeCommentsController {

    private final IHealthKnowledgeCommentsService adminCommentService;

    /**
     * 查询评论列表（支持筛选）
     *
     * @param filterDTO 筛选条件 DTO
     * @return 分页后的评论列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询心理健康知识评论列表")
    public Result<?> listComments(AdminCommentFilterDTO filterDTO) {
        log.info("管理员查询评论列表，筛选条件: {}", filterDTO);
        PageResult<AdminCommentVO> result = adminCommentService.listComments(filterDTO);
        return Result.success(result, MessageConstants.SELECT_OK);
    }

    /**
     * 新增评论
     *
     * @param commentDTO 新评论数据
     * @return 操作结果
     */
    @PostMapping("/add")
    @Operation(summary = "新增心理健康知识评论")
    public Result<?> addComment(@RequestBody @Validated AdminCommentDTO commentDTO) {
        log.info("管理员新增评论: {}", commentDTO);
        adminCommentService.addComment(commentDTO);
        return Result.success(MessageConstants.ADD_OK);
    }

    /**
     * 修改评论内容
     *
     * @param commentDTO 修改后的评论内容
     * @return 操作结果
     */
    @PutMapping("/update")
    @Operation(summary = "修改心理健康知识评论内容")
    public Result<?> updateComment(@RequestBody @Validated AdminCommentDTO commentDTO) {
        log.info("管理员修改评论: {}", commentDTO);
        adminCommentService.updateComment(commentDTO);
        return Result.success(MessageConstants.OPERATION_SUCCESSFUL);
    }

    /**
     * 批量删除评论
     *
     * @param ids 评论ID列表
     * @return 操作结果
     */
    @DeleteMapping("/deleteBatch")
    @Operation(summary = "批量删除心理健康知识评论")
    public Result<?> deleteComments(@RequestParam List<Integer> ids) {
        log.info("管理员批量删除评论ID: {}", ids);
        adminCommentService.deleteComments(ids);
        return Result.success(MessageConstants.OPERATION_SUCCESSFUL);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "评论详细信息")
    public Result<?> getById(@PathVariable Integer id) {
        log.info("管理员获取评论详细信息：{}", id);
        return Result.success(adminCommentService.finById(id), MessageConstants.SELECT_OK);
    }
}